unit InputBoxesList;
                                  
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, InputBoxes, Grids, fcLabel, ExtCtrls, StdCtrls, Mask, wwdbedit,
  Wwdotdot, Wwdbcomb, Buttons, cxStyles, cxCustomData, cxGraphics,
  cxFilter, cxData, cxDataStorage, cxEdit, cxGridCustomTableView,
  cxGridTableView, cxClasses, cxControls, cxGridCustomView, cxGridLevel,
  cxGrid, DB, cxDBData, ADODB, cxGridDBTableView, cxContainer, cxTextEdit,
  cxMaskEdit, cxDropDownEdit, cxDBEdit;

type
  TfmInputBoxesList = class(TfmInputBoxes)
    btRightAdd: TBitBtn;
    btAllRightAdd: TBitBtn;
    btLeftAdd: TBitBtn;
    btAllLeftAdd: TBitBtn;
    grSlcValues: TcxGrid;
    grSlcLevel: TcxGridLevel;
    aqAll: TADOQuery;
    dsAll: TDataSource;
    grSlcValuesDBTableView1: TcxGridDBTableView;
    aqSlc: TADOQuery;
    dsSlc: TDataSource;
    grAllValuesDBTableView1: TcxGridDBTableView;
    grAllValuesLevel1: TcxGridLevel;
    grAllValues: TcxGrid;
    edAllFilter: TcxTextEdit;
    edSlcFilter: TcxTextEdit;
    procedure btRightAddClick(Sender: TObject);
    procedure grAllValuesDBTableView1KeyDown(Sender: TObject;
      var Key: Word; Shift: TShiftState);
    procedure grAllValuesDBTableView1DblClick(Sender: TObject);
    procedure grSlcValuesDBTableView1DblClick(Sender: TObject);
    procedure edAllFilterPropertiesChange(Sender: TObject);
    procedure edSlcFilterPropertiesChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure DeleteRow(gStringGrid: TStringGrid; gRow: Integer);
  end;

var
  fmInputBoxesList: TfmInputBoxesList;

implementation

uses  data;

{$R *.dfm}

procedure TfmInputBoxesList.DeleteRow(gStringGrid: TStringGrid; gRow: Integer);
var i, j: Integer;
begin
  with gStringGrid do
  begin
    for i := gRow to RowCount - 2 do
      for j := 0 to ColCount - 1 do
        Cells[j, i] := Cells[j, i+1];
    RowCount := RowCount - 1
  end;
end;


procedure TfmInputBoxesList.btRightAddClick(Sender: TObject);
var
  intI : Integer;
begin
  inherited;
  if (Sender as TBitBtn).Tag = 1 then begin
    aqSlc.Insert;
    for intI := 0 to aqAll.Fields.Count - 1 do
      aqSlc.Fields[intI].Value := aqAll.Fields[intI].Value;
    aqSlc.Post;
    aqAll.Delete;
  end;

  if (Sender as TBitBtn).Tag = 2 then begin
    aqAll.DisableControls;
    aqAll.First;
    while not aqAll.Eof do begin
      aqSlc.Insert;
      for intI := 0 to aqAll.Fields.Count - 1 do
        aqSlc.Fields[intI].Value := aqAll.Fields[intI].Value;
      aqSlc.Post;
      aqAll.Next;
    end;
    aqAll.First;
    while not aqAll.Eof do begin
      aqAll.Next;
      aqAll.Delete;
    end;
    aqAll.EnableControls;
  end;

  if (Sender as TBitBtn).Tag = -1 then begin
    aqAll.Insert;
    for intI := 0 to aqSlc.Fields.Count - 1 do
      aqAll.Fields[intI].Value := aqSlc.Fields[intI].Value;
    aqAll.Post;
    aqSlc.Delete;
  end;

  if (Sender as TBitBtn).Tag = -2 then begin
    aqSlc.DisableControls;
    aqSlc.First;
    while not aqSlc.Eof do begin
      aqAll.Insert;
      for intI := 0 to aqSlc.Fields.Count - 1 do
        aqAll.Fields[intI].Value := aqSlc.Fields[intI].Value;
      aqAll.Post;
      aqSlc.Next;
    end;
    aqSlc.First;
    while not aqSlc.Eof do begin
      aqSlc.Next;
      aqSlc.Delete;
    end;
    aqSlc.EnableControls;
  end;
end;

procedure TfmInputBoxesList.grAllValuesDBTableView1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if TcxGridSite(Sender).GridView.Tag = 1 then begin
    if ( (ssCtrl in Shift) and (Key = 39) ) then
        btRightAdd.Click;
    if ( (ssCtrl in Shift) and (ssAlt in Shift) and (Key = 39) ) then
        btAllRightAdd.Click;
  end;

  if TcxGridSite(Sender).GridView.Tag = 2 then begin
    if ( (ssCtrl in Shift) and (Key = 37) ) then
        btLeftAdd.Click;
    if ( (ssCtrl in Shift) and (ssAlt in Shift) and (Key = 37) ) then
        btAllLeftAdd.Click;
  end;
end;

procedure TfmInputBoxesList.grAllValuesDBTableView1DblClick(
  Sender: TObject);
begin
  inherited;
  btRightAddClick(btRightAdd);
end;

procedure TfmInputBoxesList.grSlcValuesDBTableView1DblClick(
  Sender: TObject);
begin
  inherited;
  btRightAddClick(btLeftAdd);
end;

procedure TfmInputBoxesList.edAllFilterPropertiesChange(Sender: TObject);
begin
  inherited;
  if Trim(edAllFilter.Text) = '' then
    aqAll.Filtered := False
  else begin
    aqAll.Filter := '(DESCRIPTION LIKE ''' + edAllFilter.Text +'%'')';
    aqAll.Filtered := True;
  end;
end;

procedure TfmInputBoxesList.edSlcFilterPropertiesChange(Sender: TObject);
begin
  inherited;
  if Trim(edSlcFilter.Text) = '' then
    aqSlc.Filtered := False
  else begin
    aqSlc.Filter := '(DESCRIPTION LIKE ''' + edSlcFilter.Text +'%'')';
    aqSlc.Filtered := True;
  end;

end;

end.
